#!/usr/bin/env python
# -*- coding: utf-8 -*-

import unittest
import tatolib.strutil as strutil
import tatolib.taskobj as taskobj
import tatolib.errors  as errors
import tatolib.timeutil as timeutil

class TestTaskObj(unittest.TestCase):
    def test_create_tag(self):
        jing = taskobj.Tag(name = strutil.u_("Jing"),
                           detail = strutil.u_("My most important girl"),
                           weighting = 10)
        family = taskobj.Tag(name = strutil.u_("Family"),
                             detail = strutil.u_(""),
                             weighting = 1)
        work = taskobj.Tag(name = strutil.u_("Work"), 
                           detail = strutil.u_(""),
                           weighting = 1)
        # Unicode is required to name a tag
        try:
            non_unicode_name = taskobj.Tag(name="bad_name", \
                                           detail = "detail", \
                                           weighting = 1)
        except errors.TaskObjectError:
            pass
        except Exception:
            # Only TaskObjectError() is allowed
            self.assertTrue(False)
        try:
            detail_missing = taskobj.Tag(name=strutil.u_("bad"), \
                                         weighting = 1)
        except errors.TaskObjectError:
            pass
        except Exception:
            # Only TaskObjectError() is allowed
            self.assertTrue(False)
        try:
            name_missing = taskobj.Tag(detail=strutil.u_("bad"), \
                                       weighting = 1)
        except errors.TaskObjectError:
            pass
        except Exception:
            # Only TaskObjectError() is allowed
            self.assertTrue(False)
        try:
            weight_missing = taskobj.Tag(name=strutil.u_("bad"), \
                                         detail=strutil.u_("bad"))
        except errors.TaskObjectError:
            pass
        except Exception:
            # Only TaskObjectError() is allowed
            self.assertTrue(False)
    def test_flag_funcs(self):
        jing = taskobj.Task(name = strutil.u_("SayLoveToJing"),
                            detail = strutil.u_(""),
                            due = timeutil.utctoday(),
                            flags = {strutil.u_('mygirl'):   (1, False),
                                     strutil.u_('myfamily'): (10, False)})
        flagstr = jing.flagstostr()
        flags = taskobj.Task.strtoflags(flagstr) 
        self.assertTrue(flags == jing.flags)

        # Cannot add two flags with same name
        try:
            jing.addflag('mygirl', (2, False))
            self.assertTrue(False)
        except errors.TaskObjectError:
            pass
        # Cannot delete non-existing flag
        try:
            jing.delflag('mygirl2')
            self.assertTrue(False)
        except errors.TaskObjectError:
            pass


# vim:tw=78:et:sw=4
